package us.kg.kotoriforest.spring.tx.dao;

import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @author Kotori rotroutine@163.com
 * @since 2025/1/31
 */
@Repository
@AllArgsConstructor
public class AccountDao {
    private JdbcTemplate jdbcTemplate;

    public int decreaseAccountBalance(int id, BigDecimal delta) {
        String sql = "UPDATE account SET balance = balance - ? WHERE id = ?";
        return jdbcTemplate.update(sql, delta, id);
    }

    public int increaseAccountBalance(int id, BigDecimal delta) {
        return this.decreaseAccountBalance(id, delta.negate());
    }
}
